<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Demo-18</title>
    <script type="text/javascript" src="../JS/vue.js"></script>
</head>
<body>
<div id="root">
    <!-- 使用组件 -->
    <school></school>
    <hr>
    <student></student>
    <hr>
    <hello></hello>
</div>

<script>
    // 创建组件
    const school = Vue.extend({
        template: `
          <div>
          <h3>学校名称: {{ name }}</h3>
          <h3>学校地址: {{ address }}</h3>
          </div>
        `,
        data() {
            return {
                name: '尚硅谷',
                address: '北京昌平',
            }
        }
    })

    const student = Vue.extend({
        template: `
          <div>
          <h3>学生名称: {{ name }}</h3>
          <h3>学生年龄: {{ age }}</h3>
          </div>
        `,
        data() {
            return {
                name: '张三',
                age: 19,
            }
        }
    })

    const hello = Vue.extend({
        template: `
          <div>
          <h3>Hello, {{ msg }}</h3>
          </div>
        `,
        data() {
            return {
                msg: '张三'
            }
        },
    })

    // 注册组件(全局注册)
    Vue.component('hello', hello)

    new Vue({
        el: '#root',

        // 注册组件(局部注册)
        components: {
            school,
            student,
        }
    })
</script>
</body>
</html>